//
//  JXChainCode.swift
//  GodoxFlash
//
//  Created by godox on 2021/12/7.
//

import Foundation

//MARK: - 链式语法糖
public protocol JXChainCode {}

public extension JXChainCode {

    var set: Chainer<Self> {
        return Chainer(self)
    }
}

@dynamicMemberLookup
public struct Chainer<Content> {
    
    public let content: Content
    
    public var get: Content {
        return self.content
    }
    
    init(_ content: Content) {
        self.content = content
    }
    
    public subscript<Value>(dynamicMember keyPath: WritableKeyPath<Content, Value>) -> ((Value) -> Chainer<Content>) {
        var subject = self.content
        return { value in
            subject[keyPath: keyPath] = value
            return Chainer(subject)
        }
    }
}

